package com.eflow.engine.listener;

import lombok.AllArgsConstructor;
import org.flowable.engine.delegate.event.impl.FlowableEntityWithVariablesEventImpl;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.engine.interceptor.CreateUserTaskAfterContext;
import org.flowable.engine.interceptor.CreateUserTaskBeforeContext;
import org.flowable.engine.interceptor.CreateUserTaskInterceptor;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Iterator;

/** 任务创建监听器
 * @author hui se
 * @description
 * @create 2021-07-19 16:54
 **/
@AllArgsConstructor
public class TaskCreateInterceptor implements CreateUserTaskInterceptor {

    private ObjectProvider<IUserTaskCreateListener>  userTaskCreateListeners;

    @Override
    public void beforeCreateUserTask(CreateUserTaskBeforeContext context) {
        Iterator<IUserTaskCreateListener> iterator = userTaskCreateListeners.iterator();
        while(iterator.hasNext()) {
            IUserTaskCreateListener next = iterator.next();
            next.beforeCreateUserTask(context);
        }
    }

    @Override
    public void afterCreateUserTask(CreateUserTaskAfterContext context) {
        Iterator<IUserTaskCreateListener> iterator = userTaskCreateListeners.iterator();
        while(iterator.hasNext()) {
            IUserTaskCreateListener next = iterator.next();
            next.afterCreateUserTask(context);
        }
    }
}
